
/**		
 * 
 *	uk.co.lmfm.guppy.controller.CheckoutCompleteCommand
 *	
 *	@version 1.00 | Jan 14, 2010
 *	@author Justin Windle
 *  
 **/
 
package uk.co.lmfm.guppy.controller 
{
	import uk.co.lmfm.guppy.model.vo.SettingsVO;
	import uk.co.lmfm.guppy.application.enum.ApplicationConstants;
	import uk.co.lmfm.guppy.model.LibraryProxy;
	import uk.co.lmfm.guppy.model.SVNProxy;
	import uk.co.lmfm.guppy.model.SettingsProxy;
	import uk.co.lmfm.guppy.model.vo.AppStateVO;
	import uk.co.lmfm.net.subversion.vo.SVNLogReportVO;

	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;

	/**
	 * CheckoutCompleteCommand
	 */
	public class CheckoutCompleteCommand extends SimpleCommand implements ICommand 
	{
		/**
		 * notification.getName() == ApplicationConstants.CHECKOUT_COMPLETE
		 * notification.getBody() == SVNLogReportVO
		 */
		override public function execute(notification : INotification) : void
		{
			super.execute(notification);
			
			var report : SVNLogReportVO = notification.getBody() as SVNLogReportVO;
			var sqlProxy : SettingsProxy = facade.retrieveProxy(SettingsProxy.NAME) as SettingsProxy;			var libProxy : LibraryProxy = facade.retrieveProxy(LibraryProxy.NAME) as LibraryProxy;			var svnProxy : SVNProxy = facade.retrieveProxy(SVNProxy.NAME) as SVNProxy;
			var appState : AppStateVO = sqlProxy.readAppState();
			var settings : SettingsVO = sqlProxy.readSettings();
			
			appState.lastRevision = Math.max(report.latestRevisionNumber, svnProxy.latestRevisionNumber);
			sqlProxy.writeAppState(appState);
			libProxy.setLibraryPath(settings.libraryPath);
			libProxy.configureLibrary(settings);
			
			sendNotification(ApplicationConstants.UPDATE_FLEX_SDKS, true);
			sendNotification(ApplicationConstants.SET_LIBRARY_PATH);
		}
	}
}
